/*
 * iShopPlace Project.
 */
package ishopplace.view.validator.regex;

import javax.faces.validator.Validator;
import javax.faces.webapp.ValidatorTag;
import javax.servlet.jsp.JspException;

/**
 * Custom tag implementation class for the RegexValidator.
 * 
 * @author <a href="mailto:derek@derekshen.com">Derek Y. Shen</a>
 * @see RegexValidator
 */
public class RegexValidatorTag extends ValidatorTag {
	//the validator id registered in JSF
	private static String VALIDATOR_ID = "ishopplace.view.validator.Regex";
	
	//the regular expression
	private String pattern;
	
	//the error message
	private String errorMsg;
	
	public RegexValidatorTag() {
		this.setValidatorId(VALIDATOR_ID);
	}
	
	/**
	 * Create the validator associated with the tag.
	 * 
	 * @return the validator associated with the tag
	 */
	public Validator createValidator() throws JspException {
		RegexValidator validator = (RegexValidator)super.createValidator();
		validator.setRegex(this.pattern);
		validator.setErrorMsg(this.errorMsg);
		return validator;
	}
	
	public void release() {
		this.pattern = null;
		this.errorMsg = null;
	}
	
	public void setPattern(String newPattern) {
		this.pattern = newPattern;
	}
	
	public void setErrorMsg(String newErrorMsg) {
		this.errorMsg = newErrorMsg;
	}
}

